﻿var order = {
    action: "",
    msg: {
        UserId: 0,//客户编号
        Name: "",//姓名
        Operation: "",//操作人账号
        OperationName: "",//操作人姓名
        CardNo: "",//身份证
        Tel: "",//手机号码
        Action: "",//动作
        CarNo: "",//车位号
        D_ID: 0,//房间号
        Varsion: 0,//版本号
        ShopId: "",//购物车编号
        Type: 0//类型:1房间，2车位
    }
}

function resetorder() {
    order = {
        action: "",
        msg: {
            UserId: 0,//客户编号
            Name: "",//姓名
            Operation: "",//操作人账号
            OperationName: "",//操作人姓名
            CardNo: "",//身份证
            Tel: "",//手机号码
            Action: "",//动作
            CarNo: "",//车位号
            D_ID: 0,//房间号
            Varsion: 0,//版本号
            ShopId: "",//购物车编号
            Type: 0//类型:1房间，2车位
        }
    }
    return order;
}

function getRedisCommand() {
    order = resetorder();
    order.action = "redis";
    return order;
}

var action;
var wsorder = {
    //房间
    //房间落位
    roomsetting: function (operation, banname) {
        action = "roomsetting";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation, CardNo: banname };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //前端房间列表
    getallroomlist: function (operation) {
        action = "getallroomlist";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间列表
    getroomlist: function (operation) {
        action = "getroomlist";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间列表
    getroomstate: function (operation) {
        action = "getroomstate";
        order = getRedisCommand();
        var json = { Action: action };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间预定
    roomseat: function (name, operation, cardno, tel, roomid) {
        action = "roomseat";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, CardNo: cardno, Tel: tel, D_ID: parseInt(roomid) };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间预定提交
    roomcartsubmit: function (name, operation, cardno, tel, roomid, cartid) {
        action = "roomcartsubmit";
        order = getRedisCommand();
        var json = {
            Action: action, Name: name, Operation: operation, OperationName: name, CardNo: cardno, Tel: tel, D_ID: parseInt(roomid),
            ShopId: cartid
        };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间预定取消
    roomunseat: function (name, operation, cardno, tel, roomid, cartid) {
        action = "roomunseat";
        order = getRedisCommand();
        var json = {
            Action: action, Name: name, Operation: operation, OperationName: name, CardNo: cardno, Tel: tel, D_ID: parseInt(roomid),
            ShopId: cartid
        };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间引导销控准备
    setroomguidetrim: function (name, operation, roomid) {
        action = "setroomguidetrim";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, OperationName: name, D_ID: parseInt(roomid) };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间引导销控
    setroomguide: function (name, operation, roomid) {
        action = "setroomguide";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, OperationName: name, D_ID: parseInt(roomid) };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间引导销控退售
    setroomungride: function (name, operation, roomid) {
        action = "setroomunguide";
        order = getRedisCommand();
        order.msg = roomguidejson(order.msg, name, operation, action, parseInt(roomid));
        return order;
    },
    //房间后台预定
    setroomorder: function (name, operation, roomid, tel, cardno, name2, clientid) {
        action = "setroomorder";
        order = getRedisCommand();
        var json = {
            Action: action, Name: name, Operation: operation, OperationName: name2, D_ID: parseInt(roomid), CardNo: cardno, Tel: tel,
            UserId: clientid
        };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间后台预定撤销
    roomunorder: function (name, operation, roomid) {
        action = "roomunorder";
        order = getRedisCommand();
        order.msg = roomguidejson(order.msg, name, operation, action, parseInt(roomid));
        return order;
    },
    //房间后台预定翻红准备
    setroomredtrim: function (name, operation, roomid) {
        action = "setroomredtrim";
        order = getRedisCommand();
        order.msg = roomguidejson(order.msg, name, operation, action, parseInt(roomid));
        return order;
    },
    //房间后台预定翻红
    setroomred: function (name, operation, roomid) {
        action = "setroomred";
        order = getRedisCommand();
        order.msg = roomguidejson(order.msg, name, operation, action, parseInt(roomid));
        return order;
    },
    //房间后台预定取消翻红
    setroomunred: function (name, operation, roomid) {
        action = "setroomunred";
        order = getRedisCommand();
        order.msg = roomguidejson(order.msg, name, operation, action, parseInt(roomid));
        return order;
    },
    //楼栋切换
    banchange: function (operation, banname) {
        action = "banchange";
        order = getRedisCommand();
        var json = { Action: action, CarNo: banname };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间收藏修改
    roomcollectionupdate: function (operation,roomid, count) {
        action = "roomcollectionupdate";
        order = getRedisCommand();
        var json = { Action: action, D_ID: roomid, Remark: count, Operation:operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间楼栋收藏修改
    roombancollectionupdate: function (operation,banname, count) {
        action = "roombancollectionupdate";
        order = getRedisCommand();
        var json = { Action: action, Name: banname, Remark: count, Operation:operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },

    //车位
    //车位落位
    carsetting: function (operation) {
        action = "carsetting";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位列表
    getlist: function (operation) {
        action = "getlist";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation};
        order.msg = extendcommand(json, order.msg); 
        return order;
    },
    //车位区域切换
    areachange: function (operation, areaname) {
        action = "areachange";
        order = getRedisCommand();
        var json = { Action: action, CarNo: areaname };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位预约
    seat: function (name, operation, cardno, tel, carno) {
        action = "seat";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, CardNo: cardno, Tel: tel, D_ID: carno};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位预约提交
    cartsubmit: function (name, operation, cardno, tel, carno, cartid) {
        action = "cartsubmit";
        order = getRedisCommand();
        var json = {
            Action: action, Name: name, Operation: operation, CardNo: cardno, Tel: tel, D_ID: carno,
            ShopId: cartid
        };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位取消预约
    unseat: function (name, operation, cardno, tel, carno, cartid) {
        action = "unseat";
        order = getRedisCommand();
        var json = {
            Action: action, Name: name, Operation: operation, CardNo: cardno, Tel: tel, D_ID: carno,
            ShopId: cartid};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位引导销控准备
    setguide: function (name, operation, carno, varsion) {
        action = "setguide";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, D_ID: carno, Varsion: varsion };
        json.CarNo = trim(json.CarNo);
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位引导销控
    setguidetrim: function (name, operation, carno, varsion) {
        action = "setguidetrim";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, D_ID: carno, Varsion: varsion };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位取消引导
    setunguide: function (name, operation, carno, varsion) {
        action = "setunguide";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, D_ID: carno, Varsion: varsion };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位后台预定
    setorder: function (name, operation, carno, varsion) {
        action = "setorder";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, D_ID: carno, Varsion: varsion };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位取消后台预定
    unorder: function (name, operation, carno, varsion) {
        action = "unorder";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, D_ID: carno, Varsion: varsion };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位后台预定翻红
    setcarred: function (name, operation, carno, varsion) {
        action = "setcarred";
        var json = { Action: action, Name: name, Operation: operation, D_ID: carno, Varsion: varsion };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位后台预定翻红准备
    setcarredtrim: function (name, operation, carno, varsion) {
        action = "setcarredtrim";
        var json = { Action: action, Name: name, Operation: operation, D_ID: carno, Varsion: varsion };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //车位后台预定取消翻红
    setcarunred: function (name, operation, carno, varsion) {
        action = "setcarunred";
        order = getRedisCommand();
        var json = { Action: action, Name: name, Operation: operation, D_ID: carno, Varsion: varsion };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //系统操作
    //获取房间配置
    roomconfig: function (operation) {
        action = "getconfiglist";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //询问是否能增删改
    CheckToURD: function (operation) {
        action = "isstop";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //数据库更新
    updatesql: function (operation) {
        action = "updatesql";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //数据加载
    loadsql: function (operation) {
        action = "loadsql";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //项目开始，允许登陆
    setstart: function (operation) {
        action = "start";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //项目结束
    setend: function (operation) {
        action = "end";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //项目停止，全部退出
    setstop: function (operation) {
        action = "stop";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间恢复到未售状态
    dataclear: function (operation) {
        action = "clear";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //项目初始化
    allclear: function (name) {
        action = "AllClear";
        order = getRedisCommand();
        var json = { Action: action, Operation: name};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //重发短信
    smsresend: function (roomid, name) {
        action = "resend";
        order = getRedisCommand();
        var json = { Action: action, CarNo: roomid, Operation: name };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //新增认购人
    useradd: function (name, tel) {
        action = "useradd";
        order = getRedisCommand();
        var json = { Action: action, Operation: name, Tel: tel };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //删除认购人
    userdel: function (name, tel) {
        action = "userdel";
        order = getRedisCommand();
        var json = { Action: action, Operation: name, Tel: tel };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //认购人显示价格
    usershowprice: function (name, tel) {
        action = "usershowprice";
        order = getRedisCommand();
        var json = { Action: action, Operation: name, Tel: tel };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //认购人隐藏价格
    userunshowprice: function (name, tel) {
        action = "userunshowprice";
        order = getRedisCommand();
        var json = { Action: action, Operation: name, Tel: tel };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //全删认购人
    useralldel: function (name, source) {
        action = "userclear";
        order = getRedisCommand();
        var json = { Action: action, Operation: name ,};
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //加载认购人
    loadusers: function (name, source) {
        action = "loadusers";
        order = getRedisCommand();
        var json = { Action: action, Operation: name, };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //新增后台账号
    empadd: function (name, uid) {
        action = "empadd";
        order = getRedisCommand();
        var json = { Action: action, Operation: name, CarNo: uid };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //删除后台账号
    empdel: function (name, uid) {
        action = "empdel";
        order = getRedisCommand();
        var json = { Action: action, Operation: name, CarNo: uid };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //房间列表
    clearcollection: function (operation) {
        action = "clearcollection";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //加载提示表至redis
    loadtips: function (operation) {
        action = "loadtips";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //加载房间表至redis
    loadrooms: function (operation) {
        action = "loadrooms";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //客户登录锁定
    lock: function (tel, operation) {
        action = "lock";
        order = getRedisCommand();
        var json = { Action: action, Tel: tel, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //客户登录解锁
    unlock: function (tel, operation) {
        action = "unlock";
        order = getRedisCommand();
        var json = { Action: action, Tel: tel, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //客户踢出
    usergetout: function (tel, operation) {
        action = "usergetout";
        order = getRedisCommand();
        var json = { Action: action, Tel: tel, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    //后台预定开始翻红
    backorderstart: function (operation) {
        action = "backorderstart";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    getLoginTimeList: function (operation, number, time) {
    	action = "getlogintimelist";
    	order = getRedisCommand();
    	var json = { Action: action, LoginId: number, LoginTime: time, Operation: operation };
    	order.msg = extendcommand(json, order.msg);
    	return order;
    },
    setLoginTime: function (operation, time, number) {
    	action = "setlogintime";
    	order = getRedisCommand();
    	var json = { Action: action, Operation: operation, Remark:JSON.stringify( { LoginId: number, LoginTime: time}) };
    	order.msg = extendcommand(json, order.msg);
    	return order;
    },
    delLoginTime: function (operation, number) {
    	action = "dellogintime";
    	order = getRedisCommand();
    	var json = { Action: action, Operation: operation, Remark: JSON.stringify({ LoginId: number}) };
    	order.msg = extendcommand(json, order.msg);
    	return order;
    },
    mobileUserUpdate: function (operation, tels, param) {
        action = "mobileuserupdate";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation, Tel: tels, Remark: param };
        order.msg = extendcommand(json, order.msg);
        return order;
    },
    mobileUserAdd: function (operation, param) {
        action = "mobileuseradd";
        order = getRedisCommand();
        var json = { Action: action, Operation: operation, Remark: param };
        order.msg = extendcommand(json, order.msg);
        return order;
    }
	
}

function roomguidejson(json, name, operation, action, roomid, tel,cardno) {
    json.Name = name;
    json.Operation = trim(operation);
    json.OperationName = name;
    json.Action = action;
    json.D_ID = roomid;
    json.Tel = tel;
    json.CardNo = cardno;
    return json;
}

function extendcommand(json, msg) {
    var obj = $.extend(true, msg, json);
    return obj;
}

function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g, "");
}